#include <iostream>
#include <string>
#include <sstream>
#include <map>
#include "Database.h"

using namespace std;

class DbTable
{
public:
	/*
	char* dbPath | The path to the file that contains the database
	string tableName | The name of the table to query
	int id | The ID to load data about
	*/
	DbTable(char* dbPath, string tableName, int id);
	~DbTable();

	/*
	Deletes the loaded data in the database
	Returns: bool | If the data has been successfully deleted
	*/
	bool Delete();
	/*
	Get the original loaded field value
	std::string fieldName | The name of the field to get the value of
	Returns: std::string | The value for the field asked
	*/
	string Get(string fieldName);
	/*
	Checks if the id is existing in the table
	int id | The id to seek if is existing
	Returns: bool | If the id exists or not
	*/
	bool IdExists(int id);
	/*
	Loads into a map the values from the database
	Returns: map<string, string> | The map of data from the database
	*/
	map<string, string> Load();
	/*
	Saves the newly set data to the database. If the objects was not set in the database, it will be created
	Returns: int | The id of the saved data
	*/
	int Save();
	/*
	Sets a value to the given field name
	std::string fieldName | The field to add a value to
	std::string value | The value to add to the field
	*/
	void Set(string fieldName, string value);
	/*
	Represents visually (in console) the content of the table
	*/
	void ShowTable();

private:
	Database* mDb;
	string mTableName;

	int mId;
	map<string, string> mData;
	map<string, string> mNewData;
};